<?php

declare(strict_types=1);

namespace App\Http\Controllers\Manage;

use App\Http\Services\HggsyService;
use App\Repositories\FileRepository;

class HomeController extends ManageBaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {

    }

    public function test()
    {
        /*
         //更新产品sn
            $productList = Product::query()
            ->join("supplier as s", 's.id', 'product.shop_id')
            ->orderBy("product.id", "ASC")
            ->get(['product.id', 's.name', 'product.shop_id'])
            ->toArray();

        $productList = ass_column($productList, 'shop_id', true);
        foreach ($productList as $k => $products) {
            $sequence = 100000;
            $sql = "";
            foreach ($products as $sk => $v) {
                $sequence++;
                $sql = "update wx_product set `sn`='" . ($v['name'] . $sequence) . "',`sequence`={$sequence} where id={$v['id']};";

                if ($sql) {
                    DB::update(DB::raw($sql));
                }
            }
        }*/
        die();

//        $res = new FeieyunService(['id' => 2]);
        (new HggsyService())->batchData();
    }

    public function upload()
    {
        $field_key = request()->get("field_key");
        $fileData = request()->file('fileData');

        $file_type = in_array($field_key, ['cert_path', 'key_path']) ? "cert" : "member";
        $res = app(FileRepository::class)->upload($fileData, $file_type);
        $res['size'] = formatBytes($res['size']);
        $res['full_path'] = getPreviewImage($res['full_path']);

        return retSuc($res);
    }

    public function intraday()
    {
        $map['intraday'] = request()->input('intraday');
        $map['limit'] = 2;
        $reposit = new DashbordRepository();
        $activity = $reposit->getIntradayActivity($map);
        $html = view('manage.home.intraday_activity_list', [
            'activity' => $activity
        ])->render();

        return response()->json(['data' => $html]);
    }
}
